<template>
  <div id="app3">
    <header class="header">
      <div class="title">
        <img src="../../assets/images/01_11.png" alt="" class="img_zuo" @click="back" />
        <!-- <img src="../../assets/images/01_11.png" alt="" class="img_zuo" /> -->
        <div>{{title}}辖企档案</div>
        <div class="btn-add" @click="toggleMenu">
          <img src="../../assets/images/addnew.png" alt="" />
        </div>
        <div class="btn-search" @click="big">
          <img src="../../assets/images/big.png" alt="" />
        </div>
        <div class="btn-change" v-show="qx!='社区'&&qx!='企业'" @click="jumpSwitch">切换</div>
      </div>
    </header>
    <div class="main">
      <div class="item" @click="toSee('建筑物')">
        <div class="item-name">建筑物</div>
        <div class="item-value">{{ streetCount.jzwCount?streetCount.jzwCount:0 }}栋</div>
      </div>
      <div class="item" @click="toSee('九小门店')">
        <div class="item-name">九小门店</div>
        <div class="item-value">{{ streetCount.jxCount?streetCount.jxCount:0 }}户</div>
      </div>
      <div class="item" @click="toSee('住改非')">

        <div class="item-name">住改非</div>
        <div class="item-value">{{ streetCount.count?streetCount.count:0 }}户</div>

      </div>
      <div class="item" @click="toSee('企业')">
        <div class="item-name">企业</div>
        <div class="item-value">{{ streetCount.qyCount?streetCount.qyCount:0 }}户</div>
      </div>

      <div class="pop" v-show="menuFlag">
        <div class="bg" @click="toggleMenu"></div>
        <div class="pop-content radius-m">
          <img class="up_arr" src="../../assets/images/C.png" />
          <div class="content-item" @click.stop="toAdd('建筑物')">建筑物</div>
          <div class="content-item" @click.stop="toAdd('九小门店')">九小门店</div>
          <div class="content-item" @click.stop="toAdd('住改非')">住改非</div>
          <div class="content-item" @click.stop="toAdd('企业')">企业</div>
        </div>
      </div>

    </div>
    <Tabbar></Tabbar>
  </div>
</template>
<script>
  import { Toast } from 'vant';
  import Tabbar from "../tabbar.vue";
  import qs from 'qs'
  export default {
    name: "xqda",
    data() {
      return {
        menuFlag: false,
        userId: '2789',
        streetCount: {},
        auth: null,
        title: '',
        qx: '企业'
      }
    },
    components: {
      Tabbar

    },
    methods: {
      back() {
        // this.$router.push("/index");
        this.$router.back()
      },
      queryList() {
        let that = this;
        let data = {
          userId: that.userId
        }
        that.streetCount = {};
        that.axios.post(`${that.$global_msg.Url.host}/yjzgf/selectAllZgfCount`,
          qs.stringify(data)).then(res => {

            if (res.data.code === 200) {
              console.log(res)
              that.title = res.data.rows.dw;
              localStorage.setItem('Title', that.title)
              that.streetCount = res.data.rows ? res.data.rows : {};
              if (res.data.rows) {
                var lev = res.data.rows.lev;
                if (lev === 0) {
                  that.qx = '区级';
                  that.title = '渝中区';
                  localStorage.setItem('Title', that.title)
                } else if (lev === 1) {
                  that.qx = '街道';
                } else if (lev === 2) {
                  if (res.data.rows.dwlxid === 1) {
                    that.qx = '科室';
                  } else {
                    that.qx = '社区';
                  }
                } else if (lev === 3) {
                  that.qx = '企业';
                } else {
                  that.qx = '';
                }
              }
            } else {
              Toast({ message: '数据异常，请刷新页面重试' })
            }
          }).catch(error => {
            that.$terminal._error(error);
          });
      },
      jumpSwitch() {
        if (this.qx == '街道' || this.qx == '科室') {
          sessionStorage.setItem('jdid', this.streetCount.id);
          var community = {
            count: this.streetCount.count,
            jxCount: this.streetCount.jxCount,
            jzwCount: this.streetCount.jzwCount,
            qyCount: this.streetCount.qyCount,
            from: '/xqda'
          };
          sessionStorage.setItem('community', JSON.stringify(community));
          this.$router.push({
            path: '/switch_address'
          })
        } else {
          this.$router.push({
            path: '/switch'
          })
          sessionStorage.setItem('street', JSON.stringify(this.streetCount));
        }
      },
      init() {//初始化

      },
      big() {
        this.$router.push("/file_query1");
      },
      toggleMenu() {//显示或关闭菜单
        this.menuFlag = !this.menuFlag;
      },
      toAdd(type) {//跳转新增页面
        if (this.auth != 200) {
          this.$toast('没有编辑权限');
          return;
        }else{
          if(this.qx == '区级'&&(type == '建筑物'||type == '九小门店'||type == '住改非')){
            this.$toast('没有编辑权限');
            return;
          }
        }
        sessionStorage['xqda_flag'] = 1;
        if (type == '建筑物') {
          this.$router.push("/jzw_edit");
        } else if (type == '九小门店') {
          this.$router.push("/jxmd_edit");
        } else if (type == '住改非') {
          this.$router.push("/zgf_edit");
        } else if (type == '企业') {
          this.$router.push("/qy_edit");
        }
      },
      toSee(type) {//跳转查看页面
        sessionStorage['xqda_flag'] = 1;
        var index_rank = sessionStorage.getItem("index_rank");
        if (type == '建筑物') {
          sessionStorage["tongji_ct_cunt"] = 0
          sessionStorage["tongji_list_path_canshu"] = "[]"
          // this.$router.push("/jzw_tj_tu");
          if (index_rank == 1) {
            this.$router.push("/jzw_tj_tu_1");
          } else if (index_rank == 2) {
            this.$router.push("/jzw_tj_tu_2");
          } else if (index_rank == 3) {
            this.$router.push("/jzw_tj_tu_3");
          }
        } else if (type == '九小门店') {
          sessionStorage["tongji_ct_cunt"] = 0
          sessionStorage["tongji_list_path_canshu"] = "[]"
          // this.$router.push("/jxmd_tj_tu");
          if (index_rank == 1) {
            this.$router.push("/jxmd_tj_tu_1");
          } else if (index_rank == 2) {
            this.$router.push("/jxmd_tj_tu_2");
          } else if (index_rank == 3) {
            this.$router.push("/jxmd_tj_tu_3");
          }

        } else if (type == '住改非') {
          sessionStorage["tongji_ct_cunt"] = 0
          sessionStorage["tongji_list_path_canshu"] = "[]"
          // this.$router.push("/tj_tu_4");
          if (index_rank == 1) {
            this.$router.push("/tj_tu_4_1");
          } else if (index_rank == 2) {
            this.$router.push("/tj_tu_4_2");
          } else if (index_rank == 3) {
            this.$router.push("/tj_tu_4_3");
          }
        } else if (type == '企业') {
          sessionStorage["tongji_ct_cunt"] = 0
          sessionStorage["tongji_list_path_canshu"] = "[]"
          // this.$router.push("/qiye_ti_tu");
          if (index_rank == 1) {
            this.$router.push("/qiye_ti_tu_1");
          } else if (index_rank == 2) {
            this.$router.push("/qiye_ti_tu_2");
          } else if (index_rank == 3) {
            this.$router.push("/qiye_ti_tu_3");
          }
        }
      },
      checkAuth() {
        var _this = this;
        try {
          plus.nativeUI.showWaiting("正在加载...");
        } catch (e) {
          console.log(e.message);
        }
        _this.axios.get(_this.$global_msg.Url.host + "/construction/isCanBj", {
          params: {
            userid: _this.userId
          }
        }).then(function (data) {
          try {
            plus.nativeUI.closeWaiting();
          } catch (e) {
            console.log(e.message);
          }
          console.log('thisUserCanBJ:', data);
          if (data && data.data) {
            _this.auth = data.data.code;
          } else {
            _this.$toast('查询失败');
          }
        }).catch(error => {
          _this.$terminal._error(error);
        });
      },
      plusReady: function () { },
    },
    beforeCreate() {
      document.addEventListener("plusready", this.plusReady, false);
    },
    mounted() {
      var _this = this;
      //初始化
      this.userId = localStorage.getItem('userId');
      this.init();
      this.queryList();
      this.checkAuth();
      localStorage.removeItem("xcdx_map_action");

      //物理返回
      // window.addEventListener("popstate", function(){
      //   _this.back();
      // }, false);
    },
    created() {

    },
  };
</script>
<style scoped>
  .header {
    height: 1.8519rem;
    background: #007aff;
    padding-top: 0.8333rem;
    box-sizing: border-box;
    position: fixed;
    width: 100%;
    top: 0;
    z-index: 20;
    font-size: 0.388888rem;
  }

  .title {
    padding: 0 0.3704rem;
    display: flex;
    align-items: center;
    color: #fff;
    position: relative;
  }

  .title>div {
    width: 100%;
    font-size: 0.4444rem;
    text-align: center;
  }

  .img_zuo {
    width: 0.2593rem;
    height: 0.463rem;
  }

  .btn-add {
    position: absolute;
    right: 0.37037rem;
    width: auto !important;
    height: 100%;
    bottom: 0;
    display: flex;
    align-items: center;
  }

  .btn-add img {
    width: 0.529629rem;
    height: 0.529629rem;
  }

  .btn-search {
    position: absolute;
    right: 1.388888rem;
    bottom: 0;
    width: auto !important;
    height: 100%;
    display: flex;
    align-items: center;
  }

  .btn-search img {
    width: 0.529629rem;
    height: 0.529629rem;
  }

  .btn-change {
    position: absolute;
    left: 1.537037rem;
    font-size: 0.388888rem !important;
    bottom: 0;
    width: auto !important;
    height: 100%;
    display: flex;
    align-items: center;
  }

  .main {
    padding-top: 1.8519rem;
    /* height: 100vh; */
    box-sizing: border-box;
    background: #fff;
    /*padding-bottom: 3.796314814814815rem; */
    /* padding-top: 10.0008px; */
  }

  /* 圆角 */
  .radius-b {
    border-radius: 0.222222rem;
  }

  .radius-m {
    border-radius: 0.166666rem;
  }

  .radius-s {
    border-radius: 0.111111rem;
  }

  /* 表单 */
  .item {
    width: 100%;
    height: 1.388888rem;
    display: flex;
    align-items: center;
    border-bottom: 1px #DDDDDD solid;
  }

  .item .item-name {
    padding-left: 0.37037rem;
    padding-right: 0.37037rem;
    width: 2.222222rem;
    color: #000000;
    font-size: 0.388888rem;
  }

  .item .item-value {
    flex: 1;
    padding-right: 0.37037rem;
    color: #585858;
    text-align: right;
    font-size: 0.388888rem;
  }

  /* 新增菜单 */
  .pop {
    width: 100%;
    height: 100%;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 100;
  }

  .pop .bg {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 101;
  }

  .pop .pop-content {
    background-color: #686868;
    width: 2.574074rem;
    position: absolute;
    right: 0.092592rem;
    top: 2.129629rem;
    z-index: 102;
    height: auto;
  }

  .pop .content-item {
    margin-left: 0.5556rem;
    margin-right: 0.166666rem;
    padding: 0.2778rem 0;
    width: auto;
    height: auto;
    border-bottom: 1px #888 solid;
    color: #FFFFFF;
    font-size: 0.388888rem;
  }

  .pop .pop-content .up_arr {
    width: 0.666666rem;
    height: 0.481481rem;
    position: absolute;
    top: -0.222222rem;
    right: 0.111111rem;
  }
</style>
